package xyz.zhzby.cyzx.servicebase.domain;


import io.swagger.annotations.ApiModel;
import lombok.Data;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @author zby
 * @date 2021/12/06
 */
@Data
@ApiModel("分页请求封装")
public class PageRequest {
    public static final Integer DFT_PAGE_SIZE = 10;
    public static final Integer DEFAULT_PAGE_NUM = 1;

    @NotNull(message = "页码不能为空")
    @Min(value = 1L, message = "页码应该从1开始")
    private Integer page;
    private Integer limit;
    private String sortBy;
    private String order;

    public PageRequest() {
        this.page = DEFAULT_PAGE_NUM;
        this.limit = DFT_PAGE_SIZE;
    }

    private PageRequest(Integer page, Integer limit) {
        this.page = DEFAULT_PAGE_NUM;
        this.limit = DFT_PAGE_SIZE;
        this.page = page;
        this.limit = limit;
    }

    public Long getStartRow(){
        return Long.valueOf((page - 1) * limit);
    }

    public static PageRequest of(Integer page, Integer limit){
        return new PageRequest(page, limit);
    }

}
